<?php

	namespace Aspic\Log;
	
	class Logger implements \SplSubject {
		protected $observers;
		protected $logData;
		
		public function __construct() {
			$this->observers = array();
		}
		
		public function __invoke($logData) {
			return $this->log($logData);
		}
		
		/**
		* Log some data
		*/
		public function log($logData) {
			$this->logData = $logData;
			
			$this->notify();
		}
		
		public function getLogData() {
			return $this->logData;
		}
		
		public function attach(\SplObserver $observer) {
			$this->observers[] = $observer;
		}

		public function detach(\SplObserver $observer) {
			$nbObservers = count($this->observers);
			
			for($i=0; $i < $nbObservers AND $observer != $this->observers[$i];$i++);
			
			if($i < $nbObservers) {
				unset($this->observers[$i]);
			}
		}
		
		public function notify() {
			foreach($this->observers as $obs) {
				$obs->update($this);
			}
		}
	}	
	
?>